package com.cskaoyan.bean;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

/**
 * 前提是：将其注册到容器中
 * 作用范围：其他的所有组件
 * @author stone
 * @date 2022/12/20 10:54
 */
public class GlobalBeanPostProcessor implements BeanPostProcessor {
    // bean 正在执行生命周期的组件
    // beanName正在执行生命周期的组件的名称
    // 返回值：将正在生命周期的组件替换为返回值 ；return null也相当于return bean; 但是不建议return null
    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessBeforeInitialization:" + beanName);
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("postProcessAfterInitialization:" + beanName);
        return bean;
    }
}
